package com.juntu.loginlib.ui;

import android.os.Bundle;

import com.juntu.loginlib.LoginCenter;
import com.juntu.loginlib.contact.LoginConstant;
import com.juntu.loginlib.contact.LoginResultContact;
import com.juntu.loginlib.entity.LoginInfo;
import com.juntu.loginlib.ex.LoginException;
import com.juntu.loginlib.util.LoginUtil;

/**
 * Created by cj on 2021/2/19.
 * Email:codesexy@163.com
 * Function:
 * desc:
 */
abstract public class BaseLoginActivity extends BaseActivity {


    @Override
    protected void beforeInitView(Bundle savedInstanceState) {
        super.beforeInitView(savedInstanceState);
        String config = LoginUtil.getStr(LoginConstant.KEY_CONFIG);
        parseConfig(config);
    }


    public void doLogin(String userName, String userPsw, String deviceType, String placeId) {
        //开始登录成功之后需要打开主界面
        showDialog("正在登录...");
        LoginInfo info = new LoginInfo(userName, userPsw, deviceType, placeId);
        LoginCenter.getInstance().doLogin(info, new LoginResultContact() {
            @Override
            public void onSuccess(String info) {
                saveLoginInfo(info);
                dismissDialog();
                startMainActivity();
            }

            @Override
            public void onError(LoginException ex) {
                dismissDialog();
//                showDialog("登录失败,请稍候再试");
                showDialog((ex.getMessage()!=null&& ex.getMessage().length() >0)?ex.getMessage():"登录失败,请稍候再试");
            }
        });

    }

}
